#include "dspSimulator/instruction/SPLOOPW.h"

namespace dspsimulator {
    std::string SPLOOPW::to_string() const {
        return get_standard_condition(m_creg_z) + m_name + " " + get_function_unit_name(m_func_unit) + " " +
               std::to_string(m_ii);
    }

    std::shared_ptr<DspInstruction>
    SPLOOPW::decode_standard_instruction(const std::shared_ptr<DspInstructionInfo> &dsp_instruction_info) {
        std::shared_ptr<SPLOOPW> sploopw;
        std::bitset<32> &data = dsp_instruction_info->m_standard_bits;
        if (common::check_bits<21>(data, 0b000001111100000000000, 2)) {
            sploopw = std::make_shared<SPLOOPW>(dsp_instruction_info->address(), 4);
            sploopw->m_ii = common::extract_bits<5>(data, 23).to_ulong() + 1;
            sploopw->m_creg_z = common::extract_bits<4>(data, 28);
            sploopw->m_p = data[0];
        }
        return sploopw;
    }
}